//
// Created by zengao on 2022/12/29.
//

#ifndef C100_PARSER_H
#define C100_PARSER_H

#include "Lexer.h"
#include <memory>
#include "AstNode.h"
#include <unordered_map>
namespace C100 {
    class Parser {
    private:
        Lexer &lex;
        std::list<std::shared_ptr<Var>> *locals{nullptr};
        std::unordered_map<std::string_view ,std::shared_ptr<Var>> localsMap;
    public:
        Parser(Lexer &lex) : lex(lex) {}

        std::shared_ptr<ProgramNode> parse();

    private:
        std::shared_ptr<AstNode> parseStmt();

        std::shared_ptr<AstNode> parseExpr();

        std::shared_ptr<AstNode> parseAssignExpr();

        std::shared_ptr<AstNode> parseEqualExpr();

        std::shared_ptr<AstNode> parseRelationalExpr();

        std::shared_ptr<AstNode> parseAddExpr();

        std::shared_ptr<AstNode> parseMultiExpr();

        std::shared_ptr<AstNode> parsePrimaryExpr();

        std::shared_ptr<Var> findLocalVar(std::string_view name);

        std::shared_ptr<Var> makeLocalVar(std::string_view name);
    };
}


#endif //C100_PARSER_H
